<template>
    <div class="animated fadeIn register">
        <el-card class="animated bounceIn" style="

        padding: 0!important;
        ;background-color: rgba(56,59,74,0.8);border: 0!important;width: 400px;height:450px;text-align: center;">
            <h1 style=";color: #ffffff;font-weight: 600;font-size: 18px;margin-bottom: 10px">用户注册</h1>

            <el-form size="medium" :model="form" :rules="rules" ref="formRef" label-width="70px">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="form.username"></el-input>
                </el-form-item>
                <el-form-item label="邮箱" prop="email">
                    <el-input v-model="form.email"></el-input>
                </el-form-item>
                <!--                <el-form-item label="验证码" prop="nickname">-->
                <!--                    <el-input style="margin-right: 15px;width: 60%" v-model="form.nickname"></el-input>-->
                <!--                    <el-button size="small" type="primary">获取验证码</el-button>-->
                <!--                </el-form-item>-->
                <el-form-item label="密码" prop="password">
                    <el-input type="password" v-model="form.password"></el-input>
                </el-form-item>
                <el-form-item label="姓名" prop="realname">
                    <el-input v-model="form.realname"></el-input>
                </el-form-item>
                <el-form-item label="昵称" prop="nickname">
                    <el-input v-model="form.nickname"></el-input>
                </el-form-item>
                <!--                <el-form-item label="姓名" prop="password">-->
                <!--                    <el-input type="password" v-model="form.password"></el-input>-->
                <!--                </el-form-item>-->
                <!--                <el-form-item label="密码" prop="password">-->
                <!--                    <el-input type="password" v-model="form.password"></el-input>-->
                <!--                </el-form-item>-->
                <el-button style="width: 100%" @click="register('formRef')" type="success">注册</el-button>
            </el-form>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: "Register",
        data() {
            return {
                form: {
                    username: "",
                    nickname: "",
                    password: ""
                },
                rules: {
                    username: [
                        {required: true, message: '用户名不能为空', trigger: 'blur'},

                    ], nickname: [
                        {required: true, message: '昵称不能为空', trigger: 'blur'},

                    ], password: [
                        {required: true, message: '密码不能为空', trigger: 'blur'},

                    ],
                    email: [
                        {required: true, message: '邮箱不能为空', trigger: 'blur'},

                    ],
                    realname: [
                        {required: true, message: '真实姓名不能为空', trigger: 'blur'},

                    ],

                }
            }
        },
        methods: {
            register(formRef) {
                this.$refs[formRef].validate(async (valid) => { // 前端校验
                        if (valid) {
                            const {data: res} = await this.$http.post('user/register', this.form)
                            console.log(res);
                            if (res.meta.status === 200) {
                                this.$message({
                                    type: 'success',
                                    message: '注册成功，可在首页自定义头像'
                                })
                                this.$router.push('login');
                            } else {
                                this.$message({
                                    type: 'error',
                                    message: res.meta.msg
                                })
                            }

                        } else {
                            this.$message({
                                type: 'error',
                                message: '请检查！'
                            })
                            return false;
                        }
                    }
                );
            }
        }
    }
</script>

<style lang="less" scoped>
    /deep/ .el-card__body{
        /*padding: 0!important;*/
    }
/deep/ .el-button {
    border: 0!important;
    /*margin: 0!important;*/
    /*background-color: pink!important;*/
    background-color: #E04C15 !important;
    opacity: 0.9;
    /*background-color: rgba(51.169.136,0.6)!important;*/
    /*background-color: rgba(56);*/
}
    /deep/ .el-form-item__label {
        color: #fbfbfb !important;

    }

    /deep/ .el-input__inner {
        background-color: #60626E !important;
        border: 0 !important;
        color: #fbfbfb !important;
    }

    .register {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100vh;
        background-color: #E9ECEF;
        background-size: 100% 100%;
        background-repeat: no-repeat;
        background-image: url("../../assets/img/520.jpg");
        /*background-image: url("../../assets/img/img10.jpg");*/
    }
</style>